package muster;

import java.util.Iterator;
import java.util.LinkedList;

/**
 * @author:Administrator
 * @date:2022/1/20
 * @describe:
 */
public class LinkedListDome {

    public static void main(String[] args) {
        LinkedList list = new LinkedList();
        list.add(new Fruit("香蕉", 15.21));
        list.add(new Fruit("苹果", 15.21));
        list.add(new Fruit("哈密瓜", 15.21));
        list.add(new Fruit("葡萄", 15.21));

        System.out.println("第一个元素：" + list.getFirst());
        System.out.println("最后一个元素：" + list.getLast());

        list.addFirst(new Fruit("耙耙柑", 12.34));
        list.addLast(new Fruit("火龙果", 14.27));

        System.out.println("追加头和尾：" + list);

        System.out.println("------------------------------------------------------");

        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }
        System.out.println("------>>> size: " + list.size());
        list.removeFirst();
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i) + "、");
        }

        Iterator iterator = list.iterator();
        while (iterator.hasNext()) {
            Object next = iterator.next();
            System.out.println("--->>> iterator: " + next);
        }


    }
}
